<?php

/**
 * Application Models
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 * @copyright ZF model generator
 * @license http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Abstract class for models
 */
require_once 'ModelAbstract.php';

/**
 * 
 *
 * @package Application_Model
 * @subpackage Model
 * @author <YOUR NAME HERE>
 */
class Application_Model_DroitService extends Application_Model_ModelAbstract
{

    /**
     * Database var type int(11)
     *
     * @var int
     */
    protected $_IdDroitService;

    /**
     * Database var type varchar(255)
     *
     * @var string
     */
    protected $_RoleIdrole;

    /**
     * Database var type varchar(255)
     *
     * @var string
     */
    protected $_ServicesIdservices;


    /**
     * Parent relation fk_Droit_Service_role1
     *
     * @var Application_Model_Role
     */
    protected $_Role;

    /**
     * Parent relation fk_Droit_Service_services1
     *
     * @var Application_Model_Services
     */
    protected $_Services;


    /**
     * Sets up column and relationship lists
     */
    public function __construct()
    {
        parent::init();
        $this->setColumnsList(array(
            'idDroit_Service'=>'IdDroitService',
            'role_idrole'=>'RoleIdrole',
            'services_idservices'=>'ServicesIdservices',
        ));

        $this->setParentList(array(
            'FkDroitServiceRole1'=> array(
                    'property' => 'Role',
                    'table_name' => 'Role',
                ),
            'FkDroitServiceServices1'=> array(
                    'property' => 'Services',
                    'table_name' => 'Services',
                ),
        ));

        $this->setDependentList(array(
        ));
    }

    /**
     * Sets column idDroit_Service
     *
     * @param int $data
     * @return Application_Model_DroitService
     */
    public function setIdDroitService($data)
    {
        $this->_IdDroitService = $data;
        return $this;
    }

    /**
     * Gets column idDroit_Service
     *
     * @return int
     */
    public function getIdDroitService()
    {
        return $this->_IdDroitService;
    }

    /**
     * Sets column role_idrole
     *
     * @param string $data
     * @return Application_Model_DroitService
     */
    public function setRoleIdrole($data)
    {
        $this->_RoleIdrole = $data;
        return $this;
    }

    /**
     * Gets column role_idrole
     *
     * @return string
     */
    public function getRoleIdrole()
    {
        return $this->_RoleIdrole;
    }

    /**
     * Sets column services_idservices
     *
     * @param string $data
     * @return Application_Model_DroitService
     */
    public function setServicesIdservices($data)
    {
        $this->_ServicesIdservices = $data;
        return $this;
    }

    /**
     * Gets column services_idservices
     *
     * @return string
     */
    public function getServicesIdservices()
    {
        return $this->_ServicesIdservices;
    }

    /**
     * Sets parent relation RoleIdrole
     *
     * @param Application_Model_Role $data
     * @return Application_Model_DroitService
     */
    public function setRole(Application_Model_Role $data)
    {
        $this->_Role = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idrole'];
        }

        $this->setRoleIdrole($primary_key);

        return $this;
    }

    /**
     * Gets parent RoleIdrole
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Role
     */
    public function getRole($load = true)
    {
        if ($this->_Role === null && $load) {
            $this->getMapper()->loadRelated('FkDroitServiceRole1', $this);
        }

        return $this->_Role;
    }

    /**
     * Sets parent relation ServicesIdservices
     *
     * @param Application_Model_Services $data
     * @return Application_Model_DroitService
     */
    public function setServices(Application_Model_Services $data)
    {
        $this->_Services = $data;

        $primary_key = $data->getPrimaryKey();
        if (is_array($primary_key)) {
            $primary_key = $primary_key['idservices'];
        }

        $this->setServicesIdservices($primary_key);

        return $this;
    }

    /**
     * Gets parent ServicesIdservices
     *
     * @param boolean $load Load the object if it is not already
     * @return Application_Model_Services
     */
    public function getServices($load = true)
    {
        if ($this->_Services === null && $load) {
            $this->getMapper()->loadRelated('FkDroitServiceServices1', $this);
        }

        return $this->_Services;
    }

    /**
     * Returns the mapper class for this model
     *
     * @return Application_Model_Mapper_DroitService
     */
    public function getMapper()
    {
        if ($this->_mapper === null) {
            $this->setMapper(new Application_Model_Mapper_DroitService());
        }

        return $this->_mapper;
    }

    /**
     * Deletes current row by deleting the row that matches the primary key
     *
	 * @see Application_Model_Mapper_DroitService::delete
     * @return int|boolean Number of rows deleted or boolean if doing soft delete
     */
    public function deleteRowByPrimaryKey()
    {
        if ($this->getIdDroitService() === null) {
            throw new Exception('Primary Key does not contain a value');
        }

        return $this->getMapper()
                    ->getDbTable()
                    ->delete('idDroit_Service = ' .
                             $this->getMapper()
                                  ->getDbTable()
                                  ->getAdapter()
                                  ->quote($this->getIdDroitService()));
    }
}
